#ifndef TOAST_H
#define TOAST_H

#include <QWidget>
#include <QTimer>
#include <QLabel>
#include <QHBoxLayout>
#include <QGraphicsDropShadowEffect>
#include <functional>  // 添加这个头文件以支持 std::function

class Toast : public QWidget
{
    Q_OBJECT

public:
    enum ToastType {
        Info,
        Success,
        Warning,
        Error
    };

    explicit Toast(QWidget *parent = nullptr);
    ~Toast();

    // 静态显示方法 - 添加 onFinished 参数
    static void showToast(const QString& message, QWidget* parent = nullptr,
                          ToastType type = Info, int timeoutMs = 2000,
                          std::function<void()> onFinished = nullptr);

    static void info(const QString& message, QWidget* parent = nullptr, int timeoutMs = 2000);
    static void success(const QString& message, QWidget* parent = nullptr, int timeoutMs = 2000);
    static void warning(const QString& message, QWidget* parent = nullptr, int timeoutMs = 2000);
    static void error(const QString& message, QWidget* parent = nullptr, int timeoutMs = 2000);

signals:
    void finished(); // Toast显示完成信号

private slots:
    void onTimeout();

private:
    void setupUI(const QString& message, ToastType type);
    void startAnimation(int timeoutMs);
    void setToastStyle(ToastType type);
    void reposition();

private:
    QLabel *m_label;
    QTimer *m_timer;
};

#endif // TOAST_H
